package com.mlink.mapper;


import com.mlink.entity.ProjectEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ProjectMapper {

	//@Insert("INSERT INTO users(user_name,pass_word,nick_name,org,role,valid) VALUES(#{userName}, #{passWord}, #{nickName},#{org},#{role},#{valid})")

   //增加一个
	@Insert("INSERT INTO project(name,prj_dec,start,state,end) VALUES(#{name},#{describe},#{start},#{state},#{end})")

	int insert(ProjectEntity project);


//	获取所有
//	@Select("SELECT * FROM project")

	@Select("SELECT  project.id, project.name, project.prj_dec,project.start,project.end,project.state, SUM(record.working_hour) as workingHour"+
	"\tFROM record" +
	"\tRIGHT JOIN project" +
	"\tON record.project_id=project.id" +
			"\tGROUP BY project.id")

	@Results({
			@Result(property = "describe",  column = "prj_dec"),
	})
	List<ProjectEntity> getAll();

	// 根据用获取一个
	@Select("SELECT * FROM project  WHERE id = #{id}")
	@Results({
			@Result(property = "describe",  column = "prj_dec"),
	})
	ProjectEntity getOne(int id);


	//判断用户是否存在
	@Select("SELECT * FROM project  WHERE name = #{name} ")
	@Results({
			@Result(property = "describe",  column = "prj_dec"),
	})
	List<ProjectEntity> isNameEixt(@Param("name")String name);



	// 更新
	@Update("UPDATE project SET name=#{name},prj_dec=#{describe},start=#{start},end=#{end},state=#{state} WHERE id =#{id}")
	int update(ProjectEntity project);

    //删除
	@Delete("DELETE FROM project WHERE id =#{id}")
	int delete(int id);


	//使能用户无效
	@Update("UPDATE project SET state=#{state} WHERE id =#{id}")
	int setState(@Param("state") int state, @Param("id") int id);


}